var startTime;

$j(document).ready(function () {
	$j("#subButton").click(function () {
		var myDate = new Date();
		startTime = myDate.getTime();
		$j("#uploadForm").submit();
		$j("#progress").show();
		window.setTimeout("getProgressBar()", 5000);
	});
	
	$j("#cancelButton").click(function () {
		$j("#close").show();
		$j("div#info").html("文件上传被正常取消");
		//alert($j("#info").get(0).innerHTML)
		uploadAction.cancel(function () {
		});
		
	});
	$j("#close").click(function(){$j("#progress").hide();});
});

function getProgressBar() {
	var timestamp = (new Date()).valueOf();
	var total = 0;
	var success = 0;
	var fail = 0;
	var complete = 0;
	uploadAction.getProgress(function (jsonstr){
		var json = eval(jsonstr);
		total = json.total;
		success = json.success;
		fail = json.fail;
		complete=json.complete;
		if (complete == '-1') {
			$j("div#info").html("prepare to upload");
			return;
		}
		if (complete == '1') {
			$j("#close").show();
			$j("div#info").html("上传完成，总记录数:" + total + ",成功条数：" + success + "，失败条数：" + fail);
			//alert($j("#info").get(0).innerHTML)
			window.clearTimeout(interval);
			
		} else if(complete == '-2'){
			$j("#close").show();
			$j("div#info").html("请上传EXCEL格式的文件");
			//alert($j("#info").get(0).innerHTML)
			window.clearTimeout(interval);
			
		}else if(complete == '-3'){
			$j("#close").show();
			$j("div#info").html("文件上传发生异常，请联系管理员");
			//alert($j("#info").get(0).innerHTML)
			window.clearTimeout(interval);
			
		}else if(complete == '-4'){
			$j("#close").show();
			$j("div#info").html("文件上传被正常取消");
			window.clearTimeout(interval);
			
		}else if(complete == '2'){
			$j("#close").show();
			$j("div#info").html("数据上传成功，系统正在插入数据，请稍候");
			
		}else {
			$j("div#info").html("正在上传，总记录数:" + total + ",成功条数：" + success + "，失败条数：" + fail);
		}
		
	});
	
	var interval = window.setTimeout("getProgressBar()", 5000);
}

